/*
 * @Descripttion: 用户登录模块控制器
 * @version: 
 * @Author: hzx
 * @Date: 2021-03-02 11:40:59
 * @LastEditors: hzx
 * @LastEditTime: 2021-03-25 16:48:12
 */
const Controller = require('egg').Controller;

class LoginController extends Controller {
    async index() {
        this.ctx.body = "api hi"
    }

    /**
     * @name: 学生登录
     * @msg:    登录成功
     * @body { userName,password }
     * @return {*}
     */
    async studentLogin() {
        let { userName, password } = this.ctx.request.body;
        const sql = `select userName,stu_name,stu_id from student where 
        userName = '${userName}' and password = '${password}'`;

        const results = await this.app.mysql.query(sql);
        if (results.length > 0) {
            this.ctx.body = {
                code: '200',
                msg: '学生登录成功',
                data: results,
                result: true
            }
        }
    }

    /**
     * @name: 教师登录
     * @msg:  登录成功
     * @body { userName, password }
     * @return {*}
     */
    async teacherLogin() {
        let { userName, password } = this.ctx.request.body;
        const sql = `select userName,t_name,t_id from teacher where userName = '${userName}' and password = '${password}'`;

        const results = await this.app.mysql.query(sql);
        if (results.length > 0) {
            this.ctx.body = {
                code: '200',
                msg: '教师登录成功',
                data: results,
                result: true
            }
        }
    }
}


module.exports = LoginController
